import os
import pygame


# 网络上看视频找的工具代码
def load_graphics(path, accept=('.jpg', '.png', '.bmp', 'gif',)):
    graphics = {}
    for pic in os.listdir(path):
        (name, ext) = os.path.splitext(pic)
        if ext.lower() in accept:
            img = pygame.image.load(os.path.join(path, pic))
            if img.get_alpha():
                img = img.convert_alpha()
            else:
                img = img.convert()
            graphics[name] = img
    return graphics


def get_image(sheet, x, y, width, height, color_key, scale):
    image = pygame.Surface((width, height))
    image.blit(sheet, (0, 0), (x, y, width, height))
    image.set_colorkey(color_key)
    image = pygame.transform.scale(image, (int(width * scale), int(height * scale)))
    return image
